package cl.kaisanetwork.kaisaportal.page.contact;

import org.apache.click.control.FieldSet;
import org.apache.click.control.Form;
import org.apache.click.control.Option;
import org.apache.click.control.Submit;
import org.apache.click.control.TextArea;
import org.apache.click.control.TextField;
import org.apache.click.extras.control.CheckList;
import org.apache.click.util.Bindable;
import org.springframework.stereotype.Component;

import cl.kaisanetwork.kaisaportal.page.BorderPage;
import cl.kaisanetwork.kaisaportal.page.accounts.SignUp;

@Component
public class Sales extends BorderPage {

	private static final long serialVersionUID = 1L;
	
	@Bindable
	protected Form form = new Form();
	
	// Contact Fields
	private TextField txtFirstName;
	private TextField txtLastName;
	private TextField txtEmail;
	private TextField txtPhoneNumber;
	private TextField txtCompanyName;
	private TextField txtWebSite;
	
	private CheckList checkList;
	
	private TextArea txtAreaQuestBack;
	
	public Sales() {
		form.setLabelAlign(Form.ALIGN_LEFT);
        form.setLabelStyle("width:11em;");
        form.setFieldStyle("width:22em;");
        form.setColumns(4);
		
        FieldSet fieldSetContact = new FieldSet("contactSales", getMessage("contactSales"));
        
        form.add(fieldSetContact);
        
        txtFirstName = new TextField("firstName", getMessage("firstName"),  true);
    	txtLastName = new TextField("lastName", getMessage("lastName"), true);
    	txtEmail = new TextField("emal", getMessage("emal"), true);
    	txtPhoneNumber = new TextField("phoneNumber", getMessage("phoneNumber"), true);
    	txtCompanyName = new TextField("companyName", getMessage("companyName"));
    	txtWebSite = new TextField("webSite", getMessage("webSite"), true);
    	
    	txtAreaQuestBack = new TextArea("txtAreaQuestBack", getMessage("txtAreaQuestBack"), true);
        
        fieldSetContact.add(txtFirstName);
		fieldSetContact.add(txtLastName);
		fieldSetContact.add(txtEmail);
		fieldSetContact.add(txtPhoneNumber);
		fieldSetContact.add(txtCompanyName);
		fieldSetContact.add(txtWebSite);
		
		checkList = new CheckList("interestedServices", getMessage("interestedServices"), true);
		checkList.add(new Option("Hosting"));
		checkList.add(new Option("Consulting"));
		checkList.add(new Option("High Availability"));
		checkList.add(new Option("Backups"));
		checkList.add(new Option("Monitoring"));
		checkList.add(new Option("Database Adminstration"));
		checkList.add(new Option("Scaling"));
		checkList.add(new Option("Performance"));
		checkList.add(new Option("Infrastructure Automation"));
		
		fieldSetContact.add(checkList);
		
		fieldSetContact.add(txtAreaQuestBack);
		
		fieldSetContact.add(new Submit(getMessage("btnSubmit")));
		
		form.add(fieldSetContact);
		
		form.setListener(this, "onSubmit");
	}
	
	@Override
	public void onInit() {
		super.onInit();
		
		setNavMenuSelected(BorderPage.CONTACT);
		setTitle("Sales Contact Request");
		setTextTopBox("");
	}
	
	@Override
	public boolean onSecurityCheck() {
		if(!super.onSecurityCheck()) {
			setRedirect(SignUp.class);
			return false;
		}
		return true;
	}
	
	public boolean onSubmit() {
		if (!form.isValid()) {
			// msg = "Your name is " + form.getFieldValue("name");
			return false;
		}
		return true;
	}

}
